﻿
Namespace envs
    Public Module envs

        Private _assembly As Reflection.Assembly = Nothing
        Private Function assembly() As Reflection.Assembly
            If _assembly Is Nothing Then
#If Not (PocketPC OrElse Smartphone) Then
                _assembly = Reflection.Assembly.GetEntryAssembly
#End If
                If _assembly Is Nothing Then
                    _assembly = Reflection.Assembly.GetCallingAssembly
                    If _assembly Is Nothing Then
                        _assembly = Reflection.Assembly.GetExecutingAssembly
                    End If
                End If
            End If

            assert(Not _assembly Is Nothing, "cannot get any assembly information.")
            Return _assembly
        End Function

        Private _version As String = Nothing
        Public Function version() As String
            If _version Is Nothing Then
                _version = Convert.ToString(assembly().GetName().Version())
            End If

            Return _version
        End Function

        Private _shortversion As String = Nothing
        Public Function shortversion() As String
            If _shortversion Is Nothing Then
                _shortversion = Convert.ToString(assembly().GetName().Version().Major()) + character.dot + _
                                Convert.ToString(assembly().GetName().Version().Minor())
            End If

            Return _shortversion
        End Function

#If Not (PocketPC OrElse Smartphone) Then
        Private _executingFullDirectory As String = Nothing
        Public Function executingFullDirectory() As String
            If _executingFullDirectory Is Nothing Then
                _executingFullDirectory = parentpath(Windows.Forms.Application.ExecutablePath())
            End If

            Return _executingFullDirectory
        End Function

        Private _executingDirectory As String = Nothing
        Public Function executingDirectory() As String
            If _executingDirectory Is Nothing Then
                _executingDirectory = directoryName(executingFullDirectory())
            End If

            Return _executingDirectory
        End Function
#End If

        Private _name As String = Nothing
        Public Function name() As String
            If _name Is Nothing Then
                _name = assembly().GetName().Name()
            End If

            Return _name
        End Function

        Public Const debugmode As String = "debugmode"
        Public Const normalmode As String = "normalmode"
        Public Function runningMode() As String
            If isdebugmode() Then
                Return debugmode
            Else
                Return normalmode
            End If
        End Function

        Public Const debugbuild As String = "debugbuild"
        Public Const releasebuild As String = "releasebuild"
        Public Const unknownbuild As String = "unknownbuild"
        Public Function build() As String
            If isdebugbuild() Then
                Return debugbuild
            ElseIf isreleasebuild() Then
                Return releasebuild
            Else
                Return unknownbuild
            End If
        End Function

#If Not (PocketPC OrElse Smartphone) Then
        Public Function machinename() As String
            Return Global.machinename()
        End Function

        Public Function computername() As String
            Return Global.computername()
        End Function

        Private _currentLanguage As String = Nothing
        Public Function currentLanguage() As String
            If _currentLanguage Is Nothing Then
                _currentLanguage = Globalization.CultureInfo.CurrentUICulture().DisplayName()
            End If

            Return _currentLanguage
        End Function
#End If

        Private _domainname As String = Nothing
        Public Function domainname() As String
            If _domainname Is Nothing Then
                _domainname = Environment.UserDomainName()
            End If

            Return _domainname
        End Function

        Private _username As String = Nothing
        Public Function username() As String
            If _username Is Nothing Then
                _username = Environment.UserName()
            End If

            Return _username
        End Function
    End Module
End Namespace
